package cn.wolfcode.web.controller;

import cn.wolfcode.domain.Business;
import cn.wolfcode.enums.BusinessReportEnums;
import cn.wolfcode.qo.BusinessReportQueryObject;
import cn.wolfcode.service.IBusinessReportService;
import cn.wolfcode.service.IBusinessService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/customerReport")
public class CustomerReportController {
    @Autowired
    private IBusinessReportService businessReportService;
    @Autowired
    private IBusinessService businessService;

    @RequestMapping("/list")
    private String list(Model model,@ModelAttribute("qo") BusinessReportQueryObject qo) {
//          显示门店
        List<Business> businesses = businessService.listAll();
        model.addAttribute("businesses", businesses);

//        回显查询分类
        model.addAttribute("reportEnums", BusinessReportEnums.values());

//        分页
        qo.setPageSize(0);
        PageInfo pageInfo = businessReportService.query(qo);
        model.addAttribute("pageInfo", pageInfo);
        return "/businessReport/list";

    }


    @RequestMapping("/echarts")
    public String echarts(Model model,@ModelAttribute("qo") BusinessReportQueryObject qo){
        qo.setPageSize(0);
        PageInfo pageInfo = businessReportService.query(qo);
        model.addAttribute("pageInfo", pageInfo);
        return "/businessReport/echarts";
    }
}

